package org.lqk.thrift;

import org.apache.thrift.TException;
import org.apache.thrift.async.TAsyncClientManager;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TNonblockingSocket;
import org.apache.thrift.transport.TNonblockingTransport;

import java.io.IOException;

/**
 * Created by bert on 16-7-14.
 */
public class AsynClient {
    private static final String host = "localhost";
    private static final int port = 1234;
    public static void main(String[] args) {
        try {
            TAsyncClientManager clientManager = new TAsyncClientManager();
            TNonblockingTransport transport = new TNonblockingSocket(host, port, 10000);
            TProtocolFactory protocol = new TCompactProtocol.Factory();
            RemotePingService.AsyncClient asyncClient = new RemotePingService.AsyncClient(protocol, clientManager, transport);
            System.out.println("Client calls .....");
            MyCallback callBack = new MyCallback();
            asyncClient.ping(111, callBack);
            while (true) {
                Thread.sleep(1);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        }
    }
}
